#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp(x,y) make_pair((x),(y))
typedef vector<int> vi;


bool isprime(int n){
    if(n<=1)return false;
    int sqr=(int)sqrt(1.0*n);
    for(int i=2;i<=sqr;i++){
        if(n%i==0)return false;
    }
    return true;
}

int main(){
    //freopen("in.txt","r",stdin);
    int M,N;
    scanf("%d %d",&M,&N);
    while(!isprime(M)){M++;}
    bool idx[M];
    fill(idx,idx+M,false);
    vi ans;int inp;
    for(int i=0;i<N;i++){
        scanf("%d",&inp);
        int step=1,tmp=inp;
        while(idx[tmp%M] && step<M){
            tmp=inp+step*step;
            step++;
        }
        if(idx[tmp%M]==true){ans.push_back(-1);}
        else{idx[tmp%M]=true;ans.push_back(tmp%M);}
    }
    for(int i=0;i<N;i++){
        if(i==0 && ans[i]==-1){printf("-");}
        else if(i==0 && ans[i]!=-1){printf("%d",ans[i]);}
        else if(i!=0 && ans[i]==-1){printf(" -");}
        else{printf(" %d",ans[i]);}
    }
}
